#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 时间     : 2020-12-29 10:56
# 作者     : DL (584054432@qq.com)
# 网址     : https://gitee.com/dingliangPython/
# 软件版本 : Python3.7.3
# 功能     ：

import os

import sys


class Build(object):
    """docstring for Build"""

    def __init__(self, file_name):
        super(Build, self).__init__()
        self.file_name = file_name

    # 创建打包命令
    def build_command(self):
        command = (
                "from distutils.core import setup\n"
                "from Cython.Build import cythonize\n"
                "setup(ext_modules=cythonize('{}'))"
        ).format(self.file_name)
        return command

    def write_file(self, command):
        with open('./setup.py', 'w', encoding = 'utf-8') as f:
            res = f.write(command)
            return res

    # 运行
    def run(self):
        command = self.build_command()
        self.write_file(command)
        exec_command = 'python setup.py build_ext --inplace'
        os.system(exec_command)


if __name__ == '__main__':
    # args = [r'D:\CODE\PYTHON\DA_V3\app.py', 'D:\CODE\PYTHON\DA_V3\icon.ico','./']
    app = Build(*sys.argv[1:])
    # app = Build(*args)
    app.run()